class Contact < ActiveRecord::Base
    
  has_many :notes_contacts
  has_many :notes, :through => :notes_contacts
    
  #has_many :notes, :through => :notes_contacts
  
  belongs_to :project
  
  validates_presence_of :name, :surname, :profession, :email, :company
  validates_format_of :email, :with => /^[^@][\w.-]+@[\w.-]+[.][a-z]{2,4}$/i
  #validates_format_of :phone, :with => /^\d{3} \d{3} \d{4}$/, :message => "must be like XXX XXX XXXX where X represents a digit"
  #validates_format_of :fax, :with => /^\d{3} \d{3} \d{4}$/, :message => "must be like XXX XXX XXXX where X represents a digit", :allow_blank => true
  #validates_format_of :mobile, :with => /^\d{3} \d{3} \d{4}$/, :message => "phone must be like XXX XXX XXXX where X represents a digit", :allow_blank => true
  
  # if company is blank s/he is in company personnel
  def self.find_all_inhouse(project_id = 0)
    conditions = {:company => "Inhouse Personnel"}
    conditions.merge!({:project_id => project_id}) unless project_id == 0
    Contact.find(:all, :order => "name", :conditions => conditions)
  end
  
  def self.find_all
    Contact.find(:all, :order => "name")
  end
  
  def full_name
    "#{name} #{surname}"
  end
end
